(in-package :win32)


(defconstant CS_VREDRAW #x0001)
(defconstant CS_HREDRAW #x0002)
(defconstant CS_DBLCLKS #x0008)
(defconstant CS_OWNDC #x0020)
(defconstant CS_CLASSDC #x0040)
(defconstant CS_PARENTDC #x0080)
(defconstant CS_NOCLOSE #x0200)
(defconstant CS_SAVEBITS #x0800)
(defconstant CS_BYTEALIGNCLIENT #x1000)
(defconstant CS_BYTEALIGNWINDOW #x2000)
(defconstant CS_GLOBALCLASS #x4000)
(defconstant CS_IME #x00010000)
(defconstant CS_DROPSHADOW #x00020000)

(defconstant SW_HIDE            0)
(defconstant SW_SHOWNORMAL      1)
(defconstant SW_NORMAL          1)
(defconstant SW_SHOWMINIMIZED   2)
(defconstant SW_SHOWMAXIMIZED   3)
(defconstant SW_MAXIMIZE        3)
(defconstant SW_SHOWNOACTIVATE  4)
(defconstant SW_SHOW            5)
(defconstant SW_MINIMIZE        6)
(defconstant SW_SHOWMINNOACTIVE 7)
(defconstant SW_SHOWNA          8)
(defconstant SW_RESTORE         9)
(defconstant SW_SHOWDEFAULT     10)
(defconstant SW_FORCEMINIMIZE   11)

(defconstant SWP_NOSIZE           #x0001)
(defconstant SWP_NOMOVE           #x0002)
(defconstant SWP_NOZORDER         #x0004)
(defconstant SWP_NOREDRAW         #x0008)
(defconstant SWP_NOACTIVATE       #x0010)
(defconstant SWP_FRAMECHANGED     #x0020)
(defconstant SWP_SHOWWINDOW       #x0040)
(defconstant SWP_HIDEWINDOW       #x0080)
(defconstant SWP_NOCOPYBITS       #x0100)
(defconstant SWP_NOOWNERZORDER    #x0200)
(defconstant SWP_NOSENDCHANGING   #x0400)
(defconstant SWP_DRAWFRAME        SWP_FRAMECHANGED)
(defconstant SWP_NOREPOSITION     SWP_NOOWNERZORDER)
(defconstant SWP_DEFERERASE       #x2000)
(defconstant SWP_ASYNCWINDOWPOS   #x4000)

(defconstant HWND_TOP        0)
(defconstant HWND_BOTTOM     1)
(defconstant HWND_TOPMOST    -1)
(defconstant HWND_NOTOPMOST  -2)


(defconstant WS_OVERLAPPED    #x00000000)
(defconstant WS_POPUP         #x80000000)
(defconstant WS_CHILD         #x40000000)
(defconstant WS_MINIMIZE      #x20000000)
(defconstant WS_VISIBLE       #x10000000)
(defconstant WS_DISABLED      #x08000000)
(defconstant WS_CLIPSIBLINGS  #x04000000)
(defconstant WS_CLIPCHILDREN  #x02000000)
(defconstant WS_MAXIMIZE      #x01000000)
(defconstant WS_CAPTION       #x00C00000)    ; WS_BORDER  WS_DLGFRAME
(defconstant WS_BORDER        #x00800000)
(defconstant WS_DLGFRAME      #x00400000)
(defconstant WS_VSCROLL       #x00200000)
(defconstant WS_HSCROLL       #x00100000)
(defconstant WS_SYSMENU       #x00080000)
(defconstant WS_THICKFRAME    #x00040000)
(defconstant WS_GROUP         #x00020000)
(defconstant WS_TABSTOP       #x00010000)
(defconstant WS_MINIMIZEBOX   #x00020000)
(defconstant WS_MAXIMIZEBOX   #x00010000)

(defconstant WS_OVERLAPPEDWINDOW
    (logior WS_CAPTION
            WS_MAXIMIZEBOX
            WS_MINIMIZEBOX
            WS_OVERLAPPED
            WS_SYSMENU
            WS_THICKFRAME ) )

(defconstant WS_EX_DLGMODALFRAME   #x00000001)
(defconstant WS_EX_NOPARENTNOTIFY  #x00000004)
(defconstant WS_EX_TOPMOST         #x00000008)
(defconstant WS_EX_ACCEPTFILES     #x00000010)
(defconstant WS_EX_TRANSPARENT     #x00000020)
(defconstant WS_EX_MDICHILD        #x00000040)
(defconstant WS_EX_TOOLWINDOW      #x00000080)
(defconstant WS_EX_WINDOWEDGE      #x00000100)
(defconstant WS_EX_CLIENTEDGE      #x00000200)
(defconstant WS_EX_CONTEXTHELP     #x00000400)
(defconstant WS_EX_RIGHT           #x00001000)
(defconstant WS_EX_LEFT            #x00000000)
(defconstant WS_EX_RTLREADING      #x00002000)
(defconstant WS_EX_LTRREADING      #x00000000)
(defconstant WS_EX_LEFTSCROLLBAR   #x00004000)
(defconstant WS_EX_RIGHTSCROLLBAR  #x00000000)
(defconstant WS_EX_CONTROLPARENT   #x00010000)
(defconstant WS_EX_STATICEDGE      #x00020000)
(defconstant WS_EX_APPWINDOW       #x00040000)
(defconstant WS_EX_LAYERED         #x00080000)
(defconstant WS_EX_NOINHERITLAYOUT #x00100000)
(defconstant WS_EX_LAYOUTRTL       #x00400000)
(defconstant WS_EX_COMPOSITED      #x02000000)
(defconstant WS_EX_NOACTIVATE      #x08000000)

(defconstant WS_EX_OVERLAPPEDWINDOW
    (logior WS_EX_WINDOWEDGE WS_EX_CLIENTEDGE) )

(defconstant WS_EX_PALETTEWINDOW
    (logior WS_EX_WINDOWEDGE WS_EX_TOOLWINDOW WS_EX_TOPMOST) )


(defconstant WM_NULL                         #x0000)
(defconstant WM_CREATE                       #x0001)
(defconstant WM_DESTROY                      #x0002)
(defconstant WM_MOVE                         #x0003)
(defconstant WM_SIZE                         #x0005)
(defconstant WM_ACTIVATE                     #x0006)
(defconstant WM_SETFOCUS                     #x0007)
(defconstant WM_KILLFOCUS                    #x0008)
(defconstant WM_ENABLE                       #x000A)
(defconstant WM_SETREDRAW                    #x000B)
(defconstant WM_SETTEXT                      #x000C)
(defconstant WM_GETTEXT                      #x000D)
(defconstant WM_GETTEXTLENGTH                #x000E)
(defconstant WM_PAINT                        #x000F)

(defconstant WM_CLOSE                        #x0010)
(defconstant WM_QUIT                         #x0012)
(defconstant WM_QUERYENDSESSION              #x0011)
(defconstant WM_QUERYOPEN                    #x0013)
(defconstant WM_ENDSESSION                   #x0016)
(defconstant WM_ERASEBKGND                   #x0014)
(defconstant WM_SYSCOLORCHANGE               #x0015)
(defconstant WM_SHOWWINDOW                   #x0018)
(defconstant WM_WININICHANGE                 #x001A)
(defconstant WM_SETTINGCHANGE                WM_WININICHANGE)
(defconstant WM_DEVMODECHANGE                #x001B)
(defconstant WM_ACTIVATEAPP                  #x001C)
(defconstant WM_FONTCHANGE                   #x001D)
(defconstant WM_TIMECHANGE                   #x001E)
(defconstant WM_CANCELMODE                   #x001F)

(defconstant WM_SETCURSOR                    #x0020)
(defconstant WM_MOUSEACTIVATE                #x0021)
(defconstant WM_CHILDACTIVATE                #x0022)
(defconstant WM_QUEUESYNC                    #x0023)
(defconstant WM_GETMINMAXINFO                #x0024)
(defconstant WM_PAINTICON                    #x0026)
(defconstant WM_ICONERASEBKGND               #x0027)
(defconstant WM_NEXTDLGCTL                   #x0028)
(defconstant WM_SPOOLERSTATUS                #x002A)
(defconstant WM_DRAWITEM                     #x002B)
(defconstant WM_MEASUREITEM                  #x002C)
(defconstant WM_DELETEITEM                   #x002D)
(defconstant WM_VKEYTOITEM                   #x002E)
(defconstant WM_CHARTOITEM                   #x002F)

(defconstant WM_SETFONT                      #x0030)
(defconstant WM_GETFONT                      #x0031)
(defconstant WM_SETHOTKEY                    #x0032)
(defconstant WM_GETHOTKEY                    #x0033)
(defconstant WM_QUERYDRAGICON                #x0037)
(defconstant WM_COMPAREITEM                  #x0039)
(defconstant WM_GETOBJECT                    #x003D)

(defconstant WM_WINDOWPOSCHANGING            #x0046)
(defconstant WM_WINDOWPOSCHANGED             #x0047)
(defconstant WM_POWER                        #x0048)
(defconstant WM_COPYDATA                     #x004A)
(defconstant WM_CANCELJOURNAL                #x004B)
(defconstant WM_NOTIFY                       #x004E)

(defconstant WM_INPUTLANGCHANGEREQUEST       #x0050)
(defconstant WM_INPUTLANGCHANGE              #x0051)
(defconstant WM_TCARD                        #x0052)
(defconstant WM_HELP                         #x0053)
(defconstant WM_USERCHANGED                  #x0054)
(defconstant WM_NOTIFYFORMAT                 #x0055)

(defconstant WM_CONTEXTMENU                  #x007B)
(defconstant WM_STYLECHANGING                #x007C)
(defconstant WM_STYLECHANGED                 #x007D)
(defconstant WM_DISPLAYCHANGE                #x007E)
(defconstant WM_GETICON                      #x007F)

(defconstant WM_SETICON                      #x0080)
(defconstant WM_NCCREATE                     #x0081)
(defconstant WM_NCDESTROY                    #x0082)
(defconstant WM_NCCALCSIZE                   #x0083)
(defconstant WM_NCHITTEST                    #x0084)
(defconstant WM_NCPAINT                      #x0085)
(defconstant WM_NCACTIVATE                   #x0086)
(defconstant WM_GETDLGCODE                   #x0087)

(defconstant WM_NCMOUSEMOVE                  #x00A0)
(defconstant WM_NCLBUTTONDOWN                #x00A1)
(defconstant WM_NCLBUTTONUP                  #x00A2)
(defconstant WM_NCLBUTTONDBLCLK              #x00A3)
(defconstant WM_NCRBUTTONDOWN                #x00A4)
(defconstant WM_NCRBUTTONUP                  #x00A5)
(defconstant WM_NCRBUTTONDBLCLK              #x00A6)
(defconstant WM_NCMBUTTONDOWN                #x00A7)
(defconstant WM_NCMBUTTONUP                  #x00A8)
(defconstant WM_NCMBUTTONDBLCLK              #x00A9)
(defconstant WM_NCXBUTTONDOWN                #x00AB)
(defconstant WM_NCXBUTTONUP                  #x00AC)
(defconstant WM_NCXBUTTONDBLCLK              #x00AD)

(defconstant WM_INPUT                        #x00FF)

(defconstant WM_KEYFIRST                     #x0100)
(defconstant WM_KEYDOWN                      #x0100)
(defconstant WM_KEYUP                        #x0101)
(defconstant WM_CHAR                         #x0102)
(defconstant WM_DEADCHAR                     #x0103)
(defconstant WM_SYSKEYDOWN                   #x0104)
(defconstant WM_SYSKEYUP                     #x0105)
(defconstant WM_SYSCHAR                      #x0106)
(defconstant WM_SYSDEADCHAR                  #x0107)
(defconstant WM_UNICHAR                      #x0109)
(defconstant WM_KEYLAST                      #x0109)
(defconstant WM_IME_STARTCOMPOSITION         #x010D)
(defconstant WM_IME_ENDCOMPOSITION           #x010E)
(defconstant WM_IME_COMPOSITION              #x010F)
(defconstant WM_IME_KEYLAST                  #x010F)

(defconstant WM_INITDIALOG                   #x0110)
(defconstant WM_COMMAND                      #x0111)
(defconstant WM_SYSCOMMAND                   #x0112)
(defconstant WM_TIMER                        #x0113)
(defconstant WM_HSCROLL                      #x0114)
(defconstant WM_VSCROLL                      #x0115)
(defconstant WM_INITMENU                     #x0116)
(defconstant WM_INITMENUPOPUP                #x0117)
(defconstant WM_MENUSELECT                   #x011F)

(defconstant WM_MENUCHAR                     #x0120)
(defconstant WM_ENTERIDLE                    #x0121)
(defconstant WM_MENURBUTTONUP                #x0122)
(defconstant WM_MENUDRAG                     #x0123)
(defconstant WM_MENUGETOBJECT                #x0124)
(defconstant WM_UNINITMENUPOPUP              #x0125)
(defconstant WM_MENUCOMMAND                  #x0126)
(defconstant WM_CHANGEUISTATE                #x0127)
(defconstant WM_UPDATEUISTATE                #x0128)
(defconstant WM_QUERYUISTATE                 #x0129)

(defconstant WM_CTLCOLORMSGBOX               #x0132)
(defconstant WM_CTLCOLOREDIT                 #x0133)
(defconstant WM_CTLCOLORLISTBOX              #x0134)
(defconstant WM_CTLCOLORBTN                  #x0135)
(defconstant WM_CTLCOLORDLG                  #x0136)
(defconstant WM_CTLCOLORSCROLLBAR            #x0137)
(defconstant WM_CTLCOLORSTATIC               #x0138)

(defconstant WM_MOUSEFIRST                   #x0200)
(defconstant WM_MOUSEMOVE                    #x0200)
(defconstant WM_LBUTTONDOWN                  #x0201)
(defconstant WM_LBUTTONUP                    #x0202)
(defconstant WM_LBUTTONDBLCLK                #x0203)
(defconstant WM_RBUTTONDOWN                  #x0204)
(defconstant WM_RBUTTONUP                    #x0205)
(defconstant WM_RBUTTONDBLCLK                #x0206)
(defconstant WM_MBUTTONDOWN                  #x0207)
(defconstant WM_MBUTTONUP                    #x0208)
(defconstant WM_MBUTTONDBLCLK                #x0209)
(defconstant WM_MOUSEWHEEL                   #x020A)
(defconstant WM_XBUTTONDOWN                  #x020B)
(defconstant WM_XBUTTONUP                    #x020C)
(defconstant WM_XBUTTONDBLCLK                #x020D)
(defconstant WM_MOUSELAST                    #x020D)

(defconstant WM_PARENTNOTIFY                 #x0210)
(defconstant WM_ENTERMENULOOP                #x0211)
(defconstant WM_EXITMENULOOP                 #x0212)
(defconstant WM_NEXTMENU                     #x0213)
(defconstant WM_SIZING                       #x0214)
(defconstant WM_CAPTURECHANGED               #x0215)
(defconstant WM_MOVING                       #x0216)
(defconstant WM_POWERBROADCAST               #x0218)
(defconstant WM_DEVICECHANGE                 #x0219)

(defconstant WM_MDICREATE                    #x0220)
(defconstant WM_MDIDESTROY                   #x0221)
(defconstant WM_MDIACTIVATE                  #x0222)
(defconstant WM_MDIRESTORE                   #x0223)
(defconstant WM_MDINEXT                      #x0224)
(defconstant WM_MDIMAXIMIZE                  #x0225)
(defconstant WM_MDITILE                      #x0226)
(defconstant WM_MDICASCADE                   #x0227)
(defconstant WM_MDIICONARRANGE               #x0228)
(defconstant WM_MDIGETACTIVE                 #x0229)


(defconstant WM_MDISETMENU                   #x0230)
(defconstant WM_ENTERSIZEMOVE                #x0231)
(defconstant WM_EXITSIZEMOVE                 #x0232)
(defconstant WM_DROPFILES                    #x0233)
(defconstant WM_MDIREFRESHMENU               #x0234)
(defconstant WM_IME_SETCONTEXT               #x0281)
(defconstant WM_IME_NOTIFY                   #x0282)
(defconstant WM_IME_CONTROL                  #x0283)
(defconstant WM_IME_COMPOSITIONFULL          #x0284)
(defconstant WM_IME_SELECT                   #x0285)
(defconstant WM_IME_CHAR                     #x0286)
(defconstant WM_IME_REQUEST                  #x0288)

(defconstant WM_IME_KEYDOWN                  #x0290)
(defconstant WM_IME_KEYUP                    #x0291)

(defconstant WM_NCMOUSEHOVER                 #x02A0)
(defconstant WM_MOUSEHOVER                   #x02A1)
(defconstant WM_NCMOUSELEAVE                 #x02A2)
(defconstant WM_MOUSELEAVE                   #x02A3)

(defconstant WM_WTSSESSION_CHANGE            #x02B1)

(defconstant WM_TABLET_FIRST                 #x02c0)

(defconstant WM_TABLET_LAST                  #x02df)

(defconstant WM_CUT                          #x0300)
(defconstant WM_COPY                         #x0301)
(defconstant WM_PASTE                        #x0302)
(defconstant WM_CLEAR                        #x0303)
(defconstant WM_UNDO                         #x0304)
(defconstant WM_RENDERFORMAT                 #x0305)
(defconstant WM_RENDERALLFORMATS             #x0306)
(defconstant WM_DESTROYCLIPBOARD             #x0307)
(defconstant WM_DRAWCLIPBOARD                #x0308)
(defconstant WM_PAINTCLIPBOARD               #x0309)
(defconstant WM_VSCROLLCLIPBOARD             #x030A)
(defconstant WM_SIZECLIPBOARD                #x030B)
(defconstant WM_ASKCBFORMATNAME              #x030C)
(defconstant WM_CHANGECBCHAIN                #x030D)
(defconstant WM_HSCROLLCLIPBOARD             #x030E)
(defconstant WM_QUERYNEWPALETTE              #x030F)

(defconstant WM_PALETTEISCHANGING            #x0310)
(defconstant WM_PALETTECHANGED               #x0311)
(defconstant WM_HOTKEY                       #x0312)
(defconstant WM_PRINT                        #x0317)
(defconstant WM_PRINTCLIENT                  #x0318)
(defconstant WM_APPCOMMAND                   #x0319)
(defconstant WM_THEMECHANGED                 #x031A)

(defconstant WM_USER #x0400)


(defclass win32-MSG (foreign-object)
  ((hwnd :type (ptr int))           ; +0
   (message  :type uint32)          ; +4
   (wParam   :type int)             ; +8
   (lParam   :type int)             ; +12
   (time     :type uint32)          ; +16
   (pt.x     :type int32)           ; +20
   (pt.y     :type int32) )         ; +24
                                    ; +28
  (:metaclass foreign-class) )


(defclass win32-PAINTSTRUCT (foreign-object)
  ((hdc            :type (ptr int))
   (fErase         :type int32)
   (rcPaint.left   :type int32)
   (rcPant.top     :type int32)
   (rcPaint.right  :type int32)
   (rcPaint.bottom :type int32)
   (fRestore       :type int32)
   (fIncUpdate     :type int32)
   (reserved0      :type int32)
   (reserved1      :type int32)
   (reserved2      :type int32)
   (reserved3      :type int32)
   (reserved4      :type int32)
   (reserved5      :type int32)
   (reserved6      :type int32)
   (reserved7      :type int32) )
  (:metaclass foreign-class) )

;;; RECT is defined in WTypes.h


(defclass win32-WNDCLASSEX (foreign-object)
  ((cbSize        :type uint32)
   (style         :type uint32)
   (lpfnWndProc   :type (ptr int))
   (clsExtra      :type int32)
   (cbWndExtra    :type int32)
   (hInstance     :type (ptr int))
   (hIcon         :type (ptr int))
   (hCursor       :type (ptr int))
   (hbrBackground :type (ptr int))
   (lpszMenuName  :type (ptr int))
   (lpszClassName :type (ptr int))
   (hIconSm       :type (ptr int)) )
  (:metaclass foreign-class) )
